<?php
class pro_lap_gedung_model extends MY_Model {
	var $model = 'pro_lap_gedung';
	
	function GetJSON()
	{

		$ls_sql	= "	SELECT	*
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan) = 'kebersihan gedung' AND
							(UPPER(kode_perangkat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_perangkat' : post('sort'))." ".(post('order')=='' ? 'desc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_barang', $arr_data);
	}
		
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_barang', $arr_data, $arr_rule);
	}

	function UpdateJumlah($arr_data, $arr_rule){
		$this->db->update('pro_setup_stock', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_perangkat){
		$result = $this->db->get_where('pro_barang', array('kode_perangkat' => $as_kode_perangkat));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_perangkat)
	{
		$result = $this->db->get_where('pro_barang', array('kode_perangkat' => $as_kode_perangkat));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_barang WHERE kode_perangkat = '".$arr_rule['kode_perangkat']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_perangkat']."]<br />";
			}else{
				$this->db->delete('pro_barang', array('kode_perangkat' => $arr_rule['kode_perangkat']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetCetak()
	{
		$result1 = $this->db->query(" 	SELECT	*
										FROM	pro_barang
										WHERE	jenis_kebutuhan = 'Kebersihan Gedung' ");
		return $result1->row_array();
		
	}

	function GetCetakList()
	{
		$result1 = $this->db->query(" 	SELECT	*
										FROM	pro_barang
										WHERE	jenis_kebutuhan = 'Kebersihan Gedung' ");
		return $result1->result_array();
		
	}
}
?>